home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2007 September / PCWSEP07.iso / Software / Linux / Linux Mint 3.0 Light / LinuxMint-3.0-Light.iso / casper / filesystem.squashfs / var / lib / dpkg / info / x11-common.preinst < prev    next >
Encoding:
Text File  |  2007-04-02  |  33.5 KB  |  1,029 lines

  1. #!/bin/sh
  2. # Debian x11-common package pre-installation script
  3. # Copyright 1998--2001, 2003 Branden Robinson.
  4. # Licensed under the GNU General Public License, version 2.  See the file
  5. # /usr/share/common-licenses/GPL or <http://www.gnu.org/copyleft/gpl.txt>.
  6. # Acknowlegements to Stephen Early, Mark Eichin, and Manoj Srivastava.
  7.  
  8. set -e
  9.  
  10. . /usr/share/debconf/confmodule
  11.  
  12. THIS_PACKAGE=x11-common
  13. THIS_SCRIPT=preinst
  14. CONFIG_DIR=/etc/X11
  15. XWRAPPER_CONFIG="$CONFIG_DIR/Xwrapper.config"
  16. CONFIG_AUX_DIR=/var/lib/x11
  17. XWRAPPER_CONFIG_ROSTER_BASE="${XWRAPPER_CONFIG##*/}.roster"
  18. XWRAPPER_CONFIG_ROSTER="$CONFIG_AUX_DIR/$XWRAPPER_CONFIG_ROSTER_BASE"
  19. XWRAPPER_CONFIG_CHECKSUM_BASE="${XWRAPPER_CONFIG##*/}.md5sum"
  20. XWRAPPER_CONFIG_CHECKSUM="$CONFIG_AUX_DIR/$XWRAPPER_CONFIG_CHECKSUM_BASE"
  21.  
  22. # $Id$
  23.  
  24. # This is the X Strike Force shell library for X Window System package
  25. # maintainer scripts.  It serves to define shell functions commonly used by
  26. # such packages, and performs some error checking necessary for proper operation
  27. # of those functions.  By itself, it does not "do" much; the maintainer scripts
  28. # invoke the functions defined here to accomplish package installation and
  29. # removal tasks.
  30.  
  31. # If you are reading this within a Debian package maintainer script (e.g.,
  32. # /var/lib/dpkg)info/PACKAGE.{config,preinst,postinst,prerm,postrm}), you can
  33. # skip past this library by scanning forward in this file to the string
  34. # "GOBSTOPPER".
  35.  
  36. SOURCE_VERSION=1:7.2-0ubuntu11
  37. OFFICIAL_BUILD=
  38.  
  39. # Use special abnormal exit codes so that problems with this library are more
  40. # easily tracked down.
  41. SHELL_LIB_INTERNAL_ERROR=86
  42. SHELL_LIB_THROWN_ERROR=74
  43. SHELL_LIB_USAGE_ERROR=99
  44.  
  45. # old -> new variable names
  46. if [ -z "$DEBUG_XORG_PACKAGE" ] && [ -n "$DEBUG_XFREE86_PACKAGE" ]; then
  47.   DEBUG_XORG_PACKAGE="$DEBUG_XFREE86_PACKAGE"
  48. fi
  49. if [ -z "$DEBUG_XORG_DEBCONF" ] && [ -n "$DEBUG_XFREE86_DEBCONF" ]; then
  50.   DEBUG_XORG_DEBCONF="$DEBUG_XFREE86_DEBCONF"
  51. fi
  52.  
  53. # initial sanity checks
  54. if [ -z "$THIS_PACKAGE" ]; then
  55.   cat >&2 <<EOF
  56. Error: package maintainer script attempted to use shell library without
  57. definining \$THIS_PACKAGE shell variable.  Please report the package name,
  58. version, and the text of this error message to the Debian Bug Tracking System.
  59. Visit <http://www.debian.org/Bugs/Reporting> on the World Wide Web for
  60. instructions, read the file /usr/share/doc/debian/bug-reporting.txt from the
  61. "doc-debian" package, or install the "reportbug" package and use the command of
  62. the same name to file a report against version $SOURCE_VERSION of this package.
  63. EOF
  64.   exit $SHELL_LIB_USAGE_ERROR
  65. fi
  66.  
  67. if [ -z "$THIS_SCRIPT" ]; then
  68.   cat >&2 <<EOF
  69. Error: package maintainer script attempted to use shell library without
  70. definining \$THIS_SCRIPT shell variable.  Please report the package name,
  71. version, and the text of this error message to the Debian Bug Tracking System.
  72. Visit <http://www.debian.org/Bugs/Reporting> on the World Wide Web for
  73. instructions, read the file /usr/share/doc/debian/bug-reporting.txt from the
  74. "doc-debian" package, or install the "reportbug" package and use the command of
  75. the same name to file a report against version $SOURCE_VERSION of the
  76. "$THIS_PACKAGE" package.
  77. EOF
  78.   exit $SHELL_LIB_USAGE_ERROR
  79. fi
  80.  
  81. ARCHITECTURE="$(dpkg --print-installation-architecture)"
  82.  
  83. LAPTOP=""
  84. if [ -n "$(which laptop-detect)" ]; then
  85.     if laptop-detect >/dev/null; then
  86.     LAPTOP=true
  87.     fi
  88. fi
  89.  
  90. if [ "$1" = "reconfigure" ] || [ -n "$DEBCONF_RECONFIGURE" ]; then
  91.   RECONFIGURE="true"
  92. else
  93.   RECONFIGURE=
  94. fi
  95.  
  96. if ([ "$1" = "install" ] || [ "$1" = "configure" ]) && [ -z "$2" ]; then
  97.   FIRSTINST="yes"
  98. fi
  99.  
  100. if [ -z "$RECONFIGURE" ] && [ -z "$FIRSTINST" ]; then
  101.   UPGRADE="yes"
  102. fi
  103.  
  104. trap "message;\
  105.       message \"Received signal.  Aborting $THIS_PACKAGE package $THIS_SCRIPT script.\";\
  106.       message;\
  107.       exit 1" HUP INT QUIT TERM
  108.  
  109. reject_nondigits () {
  110.   # syntax: reject_nondigits [ operand ... ]
  111.   #
  112.   # scan operands (typically shell variables whose values cannot be trusted) for
  113.   # characters other than decimal digits and barf if any are found
  114.   while [ -n "$1" ]; do
  115.     # does the operand contain anything but digits?
  116.     if ! expr "$1" : "[[:digit:]]\+$" > /dev/null 2>&1; then
  117.       # can't use die(), because it wraps message() which wraps this function
  118.       echo "$THIS_PACKAGE $THIS_SCRIPT error: reject_nondigits() encountered" \
  119.            "possibly malicious garbage \"$1\"" >&2
  120.       exit $SHELL_LIB_THROWN_ERROR
  121.     fi
  122.     shift
  123.   done
  124. }
  125.  
  126. reject_whitespace () {
  127.   # syntax: reject_whitespace [ operand ]
  128.   #
  129.   # scan operand (typically a shell variable whose value cannot be trusted) for
  130.   # whitespace characters and barf if any are found
  131.   if [ -n "$1" ]; then
  132.     # does the operand contain any whitespace?
  133.     if expr "$1" : "[[:space:]]" > /dev/null 2>&1; then
  134.       # can't use die(), because I want to avoid forward references
  135.       echo "$THIS_PACKAGE $THIS_SCRIPT error: reject_whitespace() encountered" \
  136.            "possibly malicious garbage \"$1\"" >&2
  137.       exit $SHELL_LIB_THROWN_ERROR
  138.     fi
  139.   fi
  140. }
  141.  
  142. reject_unlikely_path_chars () {
  143.   # syntax: reject_unlikely_path_chars [ operand ... ]
  144.   #
  145.   # scan operands (typically shell variables whose values cannot be trusted) for
  146.   # characters unlikely to be seen in a path and which the shell might
  147.   # interpret and barf if any are found
  148.   while [ -n "$1" ]; do
  149.     # does the operand contain any funny characters?
  150.     if expr "$1" : '.*[!$&()*;<>?|].*' > /dev/null 2>&1; then
  151.       # can't use die(), because I want to avoid forward references
  152.       echo "$THIS_PACKAGE $THIS_SCRIPT error: reject_unlikely_path_chars()" \
  153.            "encountered possibly malicious garbage \"$1\"" >&2
  154.       exit $SHELL_LIB_THROWN_ERROR
  155.     fi
  156.     shift
  157.   done
  158. }
  159.  
  160. # Query the terminal to establish a default number of columns to use for
  161. # displaying messages to the user.  This is used only as a fallback in the
  162. # event the COLUMNS variable is not set.  ($COLUMNS can react to SIGWINCH while
  163. # the script is running, and this cannot, only being calculated once.)
  164. DEFCOLUMNS=$(stty size 2> /dev/null | awk '{print $2}') || true
  165. if ! expr "$DEFCOLUMNS" : "[[:digit:]]\+$" > /dev/null 2>&1; then
  166.   DEFCOLUMNS=80
  167. fi
  168.  
  169. message () {
  170.   # pretty-print messages of arbitrary length
  171.   reject_nondigits "$COLUMNS"
  172.   echo "$*" | fmt -t -w ${COLUMNS:-$DEFCOLUMNS} >&2
  173. }
  174.  
  175. observe () {
  176.   # syntax: observe message ...
  177.   #
  178.   # issue observational message suitable for logging someday when support for
  179.   # it exists in dpkg
  180.   if [ -n "$DEBUG_XORG_PACKAGE" ]; then
  181.     message "$THIS_PACKAGE $THIS_SCRIPT note: $*"
  182.   fi
  183. }
  184.  
  185. warn () {
  186.   # syntax: warn message ...
  187.   #
  188.   # issue warning message suitable for logging someday when support for
  189.   # it exists in dpkg; also send to standard error
  190.   message "$THIS_PACKAGE $THIS_SCRIPT warning: $*"
  191. }
  192.  
  193. die () {
  194.   # syntax: die message ...
  195.   #
  196.   # exit script with error message
  197.   message "$THIS_PACKAGE $THIS_SCRIPT error: $*"
  198.   exit $SHELL_LIB_THROWN_ERROR
  199. }
  200.  
  201. internal_error () {
  202.   # exit script with error; essentially a "THIS SHOULD NEVER HAPPEN" message
  203.   message "internal error: $*"
  204.   if [ -n "$OFFICIAL_BUILD" ]; then
  205.     message "Please report a bug in the $THIS_SCRIPT script of the" \
  206.             "$THIS_PACKAGE package, version $SOURCE_VERSION to the Debian Bug" \
  207.             "Tracking System.  Include all messages above that mention the" \
  208.             "$THIS_PACKAGE package.  Visit " \
  209.             "<http://www.debian.org/Bugs/Reporting> on the World Wide Web for" \
  210.             "instructions, read the file" \
  211.             "/usr/share/doc/debian/bug-reporting.txt from the doc-debian" \
  212.             "package, or install the reportbug package and use the command of" \
  213.             "the same name to file a report."
  214.   fi
  215.   exit $SHELL_LIB_INTERNAL_ERROR
  216. }
  217.  
  218. usage_error () {
  219.   message "usage error: $*"
  220.   message "Please report a bug in the $THIS_SCRIPT script of the" \
  221.           "$THIS_PACKAGE package, version $SOURCE_VERSION to the Debian Bug" \
  222.           "Tracking System.  Include all messages above that mention the" \
  223.           "$THIS_PACKAGE package.  Visit " \
  224.           "<http://www.debian.org/Bugs/Reporting> on the World Wide Web for" \
  225.           "instructions, read the file" \
  226.           "/usr/share/doc/debian/bug-reporting.txt from the doc-debian" \
  227.           "package, or install the reportbug package and use the command of" \
  228.           "the same name to file a report."
  229.   exit $SHELL_LIB_USAGE_ERROR
  230. }
  231.  
  232.  
  233. maplink () {
  234.   # returns what symlink should point to; i.e., what the "sane" answer is
  235.   # Keep this in sync with the debian/*.links files.
  236.   # This is only needed for symlinks to directories.
  237.   #
  238.   # XXX: Most of these look wrong in the X11R7 world and need to be fixed.
  239.   # If we've stopped using this function, fixing it might enable us to re-enable
  240.   # it again and catch more errors.
  241.   case "$1" in
  242.     /etc/X11/xkb/compiled) echo /var/lib/xkb ;;
  243.     /etc/X11/xkb/xkbcomp) echo /usr/X11R6/bin/xkbcomp ;;
  244.     /usr/X11R6/lib/X11/app-defaults) echo /etc/X11/app-defaults ;;
  245.     /usr/X11R6/lib/X11/fs) echo /etc/X11/fs ;;
  246.     /usr/X11R6/lib/X11/lbxproxy) echo /etc/X11/lbxproxy ;;
  247.     /usr/X11R6/lib/X11/proxymngr) echo /etc/X11/proxymngr ;;
  248.     /usr/X11R6/lib/X11/rstart) echo /etc/X11/rstart ;;
  249.     /usr/X11R6/lib/X11/twm) echo /etc/X11/twm ;;
  250.     /usr/X11R6/lib/X11/xdm) echo /etc/X11/xdm ;;
  251.     /usr/X11R6/lib/X11/xinit) echo /etc/X11/xinit ;;
  252.     /usr/X11R6/lib/X11/xkb) echo /etc/X11/xkb ;;
  253.     /usr/X11R6/lib/X11/xserver) echo /etc/X11/xserver ;;
  254.     /usr/X11R6/lib/X11/xsm) echo /etc/X11/xsm ;;
  255.     /usr/bin/X11) echo ../X11R6/bin ;;
  256.     /usr/bin/rstartd) echo ../X11R6/bin/rstartd ;;
  257.     /usr/include/X11) echo ../X11R6/include/X11 ;;
  258.     /usr/lib/X11) echo ../X11R6/lib/X11 ;;
  259.     *) internal_error "maplink() called with unknown path \"$1\"" ;;
  260.   esac
  261. }
  262.  
  263. analyze_path () {
  264.   # given a supplied set of pathnames, break each one up by directory and do an
  265.   # ls -dl on each component, cumulatively; i.e.
  266.   # analyze_path /usr/X11R6/bin -> ls -dl /usr /usr/X11R6 /usr/X11R6/bin
  267.   # Thanks to Randolph Chung for this clever hack.
  268.  
  269.   #local f g
  270.  
  271.   while [ -n "$1" ]; do
  272.     reject_whitespace "$1"
  273.     _g=
  274.     message "Analyzing $1:"
  275.     for _f in $(echo "$1" | tr / \  ); do
  276.       if [ -e /$_g$_f ]; then
  277.         ls -dl /$_g$_f /$_g$_f.dpkg-* 2> /dev/null || true
  278.         _g=$_g$_f/
  279.       else
  280.         message "/$_g$_f: nonexistent; directory contents of /$_g:"
  281.         ls -l /$_g
  282.         break
  283.       fi
  284.     done
  285.     shift
  286.   done
  287. }
  288.  
  289. find_culprits () {
  290.   #local f p dpkg_info_dir possible_culprits smoking_guns bad_packages package \
  291.   #  msg
  292.  
  293.   reject_whitespace "$1"
  294.   message "Searching for overlapping packages..."
  295.   _dpkg_info_dir=/var/lib/dpkg/info
  296.   if [ -d $_dpkg_info_dir ]; then
  297.     if [ "$(echo $_dpkg_info_dir/*.list)" != "$_dpkg_info_dir/*.list" ]; then
  298.       _possible_culprits=$(ls -1 $_dpkg_info_dir/*.list | egrep -v \
  299.         "(xbase-clients|x11-common|xfs|xlibs)")
  300.       if [ -n "$_possible_culprits" ]; then
  301.         _smoking_guns=$(grep -l "$1" $_possible_culprits || true)
  302.         if [ -n "$_smoking_guns" ]; then
  303.           _bad_packages=$(printf "\\n")
  304.           for f in $_smoking_guns; do
  305.             # too bad you can't nest parameter expansion voodoo
  306.             p=${f%*.list}      # strip off the trailing ".list"
  307.             _package=${p##*/}   # strip off the directories
  308.             _bad_packages=$(printf "%s\n%s" "$_bad_packages" "$_package")
  309.           done
  310.           _msg=$(cat <<EOF
  311. The following packages appear to have file overlaps with the X.Org packages;
  312. these packages are either very old, or in violation of Debian Policy.  Try
  313. upgrading each of these packages to the latest available version if possible:
  314. for example, with the command "apt-get install".  If no newer version of a
  315. package is available, you will have to remove it; for example, with the command
  316. "apt-get remove".  If even the latest available version of the package has
  317. this file overlap, please file a bug against that package with the Debian Bug
  318. Tracking System.  You may want to refer the package maintainer to section 12.8
  319. of the Debian Policy manual.
  320. EOF
  321. )
  322.           message "$_msg"
  323.           message "The overlapping packages are: $_bad_packages"
  324.         else
  325.           message "no overlaps found."
  326.         fi
  327.       fi
  328.     else
  329.       message "cannot search; no matches for $_dpkg_info_dir/*.list."
  330.     fi
  331.   else
  332.     message "cannot search; $_dpkg_info_dir does not exist."
  333.   fi
  334. }
  335.  
  336. # we require a readlink command or shell function
  337. if ! which readlink > /dev/null 2>&1; then
  338.   message "The readlink command was not found.  Please install version" \
  339.           "1.13.1 or later of the debianutils package."
  340.   readlink () {
  341.     # returns what symlink in $1 actually points to
  342.     perl -e '$l = shift; exit 1 unless -l $l; $r = readlink $l; exit 1 unless $r; print "$r\n"' "$1"
  343.   }
  344. fi
  345.  
  346. check_symlink () {
  347.   # syntax: check_symlink symlink
  348.   #
  349.   # See if specified symlink points where it is supposed to.  Return 0 if it
  350.   # does, and 1 if it does not.
  351.   #
  352.   # Primarily used by check_symlinks_and_warn() and check_symlinks_and_bomb().
  353.  
  354.   #local symlink
  355.  
  356.   # validate arguments
  357.   if [ $# -ne 1 ]; then
  358.     usage_error "check_symlink() called with wrong number of arguments;" \
  359.                 "expected 1, got $#"
  360.     exit $SHELL_LIB_USAGE_ERROR
  361.   fi
  362.  
  363.   _symlink="$1"
  364.  
  365.   if [ "$(maplink "$_symlink")" = "$(readlink "$_symlink")" ]; then
  366.     return 0
  367.   else
  368.     return 1
  369.   fi
  370. }
  371.  
  372. check_symlinks_and_warn () {
  373.   # syntax: check_symlinks_and_warn symlink ...
  374.   #
  375.   # For each argument, check for symlink sanity, and warn if it isn't sane.
  376.   #
  377.   # Call this function from a preinst script in the event $1 is "upgrade" or
  378.   # "install".
  379.  
  380.   #local errmsg symlink
  381.  
  382.   # validate arguments
  383.   if [ $# -lt 1 ]; then
  384.     usage_error "check_symlinks_and_warn() called with wrong number of" \
  385.                 "arguments; expected at least 1, got $#"
  386.     exit $SHELL_LIB_USAGE_ERROR
  387.   fi
  388.  
  389.   while [ -n "$1" ]; do
  390.     _symlink="$1"
  391.     if [ -L "$_symlink" ]; then
  392.       if ! check_symlink "$_symlink"; then
  393.         observe "$_symlink symbolic link points to wrong location" \
  394.                 "$(readlink "$_symlink"); removing"
  395.         rm "$_symlink"
  396.       fi
  397.     elif [ -e "$_symlink" ]; then
  398.       _errmsg="$_symlink exists and is not a symbolic link; this package cannot"
  399.       _errmsg="$_errmsg be installed until this"
  400.       if [ -f "$_symlink" ]; then
  401.         _errmsg="$_errmsg file"
  402.       elif [ -d "$_symlink" ]; then
  403.         _errmsg="$_errmsg directory"
  404.       else
  405.         _errmsg="$_errmsg thing"
  406.       fi
  407.       _errmsg="$_errmsg is removed"
  408.       die "$_errmsg"
  409.     fi
  410.     shift
  411.   done
  412. }
  413.  
  414. check_symlinks_and_bomb () {
  415.   # syntax: check_symlinks_and_bomb symlink ...
  416.   #
  417.   # For each argument, check for symlink sanity, and bomb if it isn't sane.
  418.   #
  419.   # Call this function from a postinst script.
  420.  
  421.   #local problem symlink
  422.  
  423.   # validate arguments
  424.   if [ $# -lt 1 ]; then
  425.     usage_error "check_symlinks_and_bomb() called with wrong number of"
  426.                 "arguments; expected at least 1, got $#"
  427.     exit $SHELL_LIB_USAGE_ERROR
  428.   fi
  429.  
  430.   while [ -n "$1" ]; do
  431.     _problem=
  432.     _symlink="$1"
  433.     if [ -L "$_symlink" ]; then
  434.       if ! check_symlink "$_symlink"; then
  435.         _problem=yes
  436.         warn "$_symlink symbolic link points to wrong location" \
  437.              "$(readlink "$_symlink")"
  438.       fi
  439.     elif [ -e "$_symlink" ]; then
  440.       _problem=yes
  441.       warn "$_symlink is not a symbolic link"
  442.     else
  443.       _problem=yes
  444.       warn "$_symlink symbolic link does not exist"
  445.     fi
  446.     if [ -n "$_problem" ]; then
  447.       analyze_path "$_symlink" "$(readlink "$_symlink")"
  448.       find_culprits "$_symlink"
  449.       die "bad symbolic links on system"
  450.     fi
  451.     shift
  452.   done
  453. }
  454.  
  455. font_update () {
  456.   # run $UPDATECMDS in $FONTDIRS
  457.  
  458.   #local dir cmd shortcmd x_font_dir_prefix
  459.  
  460.   _x_font_dir_prefix="/usr/share/fonts/X11"
  461.  
  462.   if [ -z "$UPDATECMDS" ]; then
  463.     usage_error "font_update() called but \$UPDATECMDS not set"
  464.   fi
  465.   if [ -z "$FONTDIRS" ]; then
  466.     usage_error "font_update() called but \$FONTDIRS not set"
  467.   fi
  468.  
  469.   reject_unlikely_path_chars "$UPDATECMDS"
  470.   reject_unlikely_path_chars "$FONTDIRS"
  471.  
  472.   for _dir in $FONTDIRS; do
  473.     if [ -d "$_x_font_dir_prefix/$_dir" ]; then
  474.       for _cmd in $UPDATECMDS; do
  475.         if which "$_cmd" > /dev/null 2>&1; then
  476.           _shortcmd=${_cmd##*/}
  477.           observe "running $_shortcmd in $_dir font directory"
  478.       _cmd_opts=
  479.           if [ "$_shortcmd" = "update-fonts-alias" ]; then
  480.             _cmd_opts=--x11r7-layout
  481.           fi
  482.           if [ "$_shortcmd" = "update-fonts-dir" ]; then
  483.             _cmd_opts=--x11r7-layout
  484.           fi
  485.           if [ "$_shortcmd" = "update-fonts-scale" ]; then
  486.             _cmd_opts=--x11r7-layout
  487.           fi
  488.           $_cmd $_cmd_opts $_dir || warn "$_cmd $_cmd_opts $_dir" \
  489.                               "failed; font directory data may not" \
  490.                               "be up to date"
  491.         else
  492.           warn "$_cmd not found; not updating corresponding $_dir font" \
  493.                "directory data"
  494.         fi
  495.       done
  496.     else
  497.       warn "$_dir is not a directory; not updating font directory data"
  498.     fi
  499.   done
  500. }
  501.  
  502. remove_conffile_prepare () {
  503.   # syntax: remove_conffile_prepare filename official_md5sum ...
  504.   #
  505.   # Check a conffile "filename" against a list of canonical MD5 checksums.
  506.   # If the file's current MD5 checksum matches one of the "official_md5sum"
  507.   # operands provided, then prepare the conffile for removal from the system.
  508.   # We defer actual deletion until the package is configured so that we can
  509.   # roll this operation back if package installation fails.
  510.   #
  511.   # Call this function from a preinst script in the event $1 is "upgrade" or
  512.   # "install" and verify $2 to ensure the package is being upgraded from a
  513.   # version (or installed over a version removed-but-not-purged) prior to the
  514.   # one in which the conffile was obsoleted.
  515.  
  516.   #local conffile current_checksum
  517.  
  518.   # validate arguments
  519.   if [ $# -lt 2 ]; then
  520.     usage_error "remove_conffile_prepare() called with wrong number of" \
  521.                 "arguments; expected at least 2, got $#"
  522.     exit $SHELL_LIB_USAGE_ERROR
  523.   fi
  524.  
  525.   _conffile="$1"
  526.   shift
  527.  
  528.   # does the _conffile even exist?
  529.   if [ -e "$_conffile" ]; then
  530.     # calculate its checksum
  531.     _current_checksum=$(md5sum < "$_conffile" | sed 's/[[:space:]].*//')
  532.     # compare it to each supplied checksum
  533.     while [ -n "$1" ]; do
  534.       if [ "$_current_checksum" = "$1" ]; then
  535.         # we found a match; move the confffile and stop looking
  536.         observe "preparing obsolete conffile $_conffile for removal"
  537.         mv "$_conffile" "$_conffile.$THIS_PACKAGE-tmp"
  538.         break
  539.       fi
  540.       shift
  541.     done
  542.   fi
  543. }
  544.  
  545. remove_conffile_commit () {
  546.   # syntax: remove_conffile_commit filename
  547.   #
  548.   # Complete the removal of a conffile "filename" that has become obsolete.
  549.   #
  550.   # Call this function from a postinst script after having used
  551.   # remove_conffile_prepare() in the preinst.
  552.  
  553.   #local conffile
  554.  
  555.   # validate arguments
  556.   if [ $# -ne 1 ]; then
  557.     usage_error "remove_conffile_commit() called with wrong number of" \
  558.                 "arguments; expected 1, got $#"
  559.     exit $SHELL_LIB_USAGE_ERROR
  560.   fi
  561.  
  562.   _conffile="$1"
  563.  
  564.   # if the temporary file created by remove_conffile_prepare() exists, remove it
  565.   if [ -e "$_conffile.$THIS_PACKAGE-tmp" ]; then
  566.     observe "committing removal of obsolete conffile $_conffile"
  567.     rm "$_conffile.$THIS_PACKAGE-tmp"
  568.   fi
  569. }
  570.  
  571. remove_conffile_rollback () {
  572.   # syntax: remove_conffile_rollback filename
  573.   #
  574.   # Roll back the removal of a conffile "filename".
  575.   #
  576.   # Call this function from a postrm script in the event $1 is "abort-upgrade"
  577.   # or "abort-install" is  after having used remove_conffile_prepare() in the
  578.   # preinst.
  579.  
  580.   #local conffile
  581.  
  582.   # validate arguments
  583.   if [ $# -ne 1 ]; then
  584.     usage_error "remove_conffile_rollback() called with wrong number of" \
  585.                 "arguments; expected 1, got $#"
  586.     exit $SHELL_LIB_USAGE_ERROR
  587.   fi
  588.  
  589.   _conffile="$1"
  590.  
  591.   # if the temporary file created by remove_conffile_prepare() exists, move it
  592.   # back
  593.   if [ -e "$_conffile.$THIS_PACKAGE-tmp" ]; then
  594.     observe "rolling back removal of obsolete conffile $_conffile"
  595.     mv "$_conffile.$THIS_PACKAGE-tmp" "$_conffile"
  596.   fi
  597. }
  598.  
  599. replace_conffile_with_symlink_prepare () {
  600.   # syntax: replace_conffile_with_symlink_prepare oldfilename newfilename \
  601.   # official_md5sum ...
  602.   #
  603.   # Check a conffile "oldfilename" against a list of canonical MD5 checksums.
  604.   # If the file's current MD5 checksum matches one of the "official_md5sum"
  605.   # operands provided, then prepare the conffile for removal from the system.
  606.   # We defer actual deletion until the package is configured so that we can
  607.   # roll this operation back if package installation fails. Otherwise copy it
  608.   # to newfilename and let dpkg handle it through conffiles mechanism.
  609.   #
  610.   # Call this function from a preinst script in the event $1 is "upgrade" or
  611.   # "install" and verify $2 to ensure the package is being upgraded from a
  612.   # version (or installed over a version removed-but-not-purged) prior to the
  613.   # one in which the conffile was obsoleted.
  614.  
  615.   #local conffile current_checksum
  616.  
  617.   # validate arguments
  618.   if [ $# -lt 3 ]; then
  619.     usage_error "replace_conffile_with_symlink_prepare() called with wrong" \
  620.                 " number of arguments; expected at least 3, got $#"
  621.     exit $SHELL_LIB_USAGE_ERROR
  622.   fi
  623.  
  624.   _oldconffile="$1"
  625.   shift
  626.   _newconffile="$1"
  627.   shift
  628.  
  629.   remove_conffile_prepare "$_oldconffile" "$@"
  630.   # If $_oldconffile still exists, then md5sums didn't match.
  631.   # Copy it to new one.
  632.   if [ -f "$_oldconffile" ]; then
  633.     cp "$_oldconffile" "$_newconffile"
  634.   fi
  635.  
  636. }
  637.  
  638. replace_conffile_with_symlink_commit () {
  639.   # syntax: replace_conffile_with_symlink_commit oldfilename
  640.   #
  641.   # Complete the removal of a conffile "oldfilename" that has been
  642.   # replaced by a symlink.
  643.   #
  644.   # Call this function from a postinst script after having used
  645.   # replace_conffile_with_symlink_prepare() in the preinst.
  646.  
  647.   #local conffile
  648.  
  649.   # validate arguments
  650.   if [ $# -ne 1 ]; then
  651.     usage_error "replace_conffile_with_symlink_commit() called with wrong" \
  652.                 "number of arguments; expected 1, got $#"
  653.     exit $SHELL_LIB_USAGE_ERROR
  654.   fi
  655.  
  656.   _conffile="$1"
  657.  
  658.   remove_conffile_commit "$_conffile"
  659. }
  660.  
  661. replace_conffile_with_symlink_rollback () {
  662.   # syntax: replace_conffile_with_symlink_rollback oldfilename newfilename
  663.   #
  664.   # Roll back the replacing of a conffile "oldfilename" with symlink to
  665.   # "newfilename".
  666.   #
  667.   # Call this function from a postrm script in the event $1 is "abort-upgrade"
  668.   # or "abort-install" and verify $2 to ensure the package failed to upgrade
  669.   # from a version (or install over a version removed-but-not-purged) prior
  670.   # to the one in which the conffile was obsoleted.
  671.   # You should have  used replace_conffile_with_symlink_prepare() in the
  672.   # preinst.
  673.  
  674.   #local conffile
  675.  
  676.   # validate arguments
  677.   if [ $# -ne 2 ]; then
  678.     usage_error "replace_conffile_with_symlink_rollback() called with wrong" \
  679.                 "number of arguments; expected 2, got $#"
  680.     exit $SHELL_LIB_USAGE_ERROR
  681.   fi
  682.  
  683.   _oldconffile="$1"
  684.   _newconffile="$2"
  685.  
  686.   remove_conffile_rollback "$_oldconffile"
  687.   if [ -f "$_newconffile" ]; then
  688.     rm "$_newconffile"
  689.   fi
  690. }
  691.  
  692. run () {
  693.   # syntax: run command [ argument ... ]
  694.   #
  695.   # Run specified command with optional arguments and report its exit status.
  696.   # Useful for commands whose exit status may be nonzero, but still acceptable,
  697.   # or commands whose failure is not fatal to us.
  698.   #
  699.   # NOTE: Do *not* use this function with db_get or db_metaget commands; in
  700.   # those cases the return value of the debconf command *must* be checked
  701.   # before the string returned by debconf is used for anything.
  702.  
  703.   #local retval
  704.  
  705.   # validate arguments
  706.   if [ $# -lt 1 ]; then
  707.     usage_error "run() called with wrong number of arguments; expected at" \
  708.                 "least 1, got $#"
  709.     exit $SHELL_LIB_USAGE_ERROR
  710.   fi
  711.  
  712.   "$@" || _retval=$?
  713.  
  714.   if [ ${_retval:-0} -ne 0 ]; then
  715.     observe "command \"$*\" exited with status $_retval"
  716.   fi
  717. }
  718.  
  719. register_x_lib_dir_with_ld_so () {
  720.   # syntax: register_x_lib_dir_with_ld_so
  721.   #
  722.   # Configure the dynamic loader ld.so to search /usr/X11R6/lib for shared
  723.   # libraries.
  724.   #
  725.   # Call this function from the postinst script of a package that places a
  726.   # shared library in /usr/X11R6/lib, before invoking ldconfig.
  727.  
  728.   #local dir ldsoconf
  729.  
  730.   _dir="/usr/X11R6/lib"
  731.   _ldsoconf="/etc/ld.so.conf"
  732.  
  733.   # is the line not already present?
  734.   if ! fgrep -qsx "$_dir" "$_ldsoconf"; then
  735.     observe "adding $_dir directory to $_ldsoconf"
  736.     echo "$_dir" >> "$_ldsoconf"
  737.   fi
  738. }
  739.  
  740. deregister_x_lib_dir_with_ld_so () {
  741.   # syntax: deregister_x_lib_dir_with_ld_so
  742.   #
  743.   # Configure dynamic loader ld.so to not search /usr/X11R6/lib for shared
  744.   # libraries, if and only if no shared libaries remain there.
  745.   #
  746.   # Call this function from the postrm script of a package that places a shared
  747.   # library in /usr/X11R6/lib, in the event "$1" is "remove", and before
  748.   # invoking ldconfig.
  749.  
  750.   #local dir ldsoconf fgrep_status cmp_status
  751.  
  752.   _dir="/usr/X11R6/lib"
  753.   _ldsoconf="/etc/ld.so.conf"
  754.  
  755.   # is the line present?
  756.   if fgrep -qsx "$_dir" "$_ldsoconf"; then
  757.     # are there any shared objects in the directory?
  758.     if [ "$(echo "$_dir"/lib*.so.*.*)" = "$_dir/lib*.so.*.*" ]; then
  759.       # glob expansion produced nothing, so no shared libraries are present
  760.       observe "removing $_dir directory from $_ldsoconf"
  761.       # rewrite the file (very carefully)
  762.       set +e
  763.       fgrep -svx "$_dir" "$_ldsoconf" > "$_ldsoconf.dpkg-tmp"
  764.       _fgrep_status=$?
  765.       set -e
  766.       case $_fgrep_status in
  767.         0|1) ;; # we don't actually care if any lines matched or not
  768.         *) die "error reading \"$_ldsoconf\"; fgrep exited with status" \
  769.           "$_fgrep_status" ;;
  770.       esac
  771.       set +e
  772.       cmp -s "$_ldsoconf.dpkg-tmp" "$_ldsoconf"
  773.       _cmp_status=$?
  774.       set -e
  775.       case $_cmp_status in
  776.         0) rm "$_ldsoconf.dpkg-tmp" ;; # files are identical
  777.         1) mv "$_ldsoconf.dpkg-tmp" "$_ldsoconf" ;; # files differ
  778.         *) die "error comparing \"$_ldsoconf.dpkg-tmp\" to \"$_ldsoconf\";" \
  779.           "cmp exited with status $_cmp_status" ;;
  780.       esac
  781.     fi
  782.   fi
  783. }
  784.  
  785. make_symlink_sane () {
  786.   # syntax: make_symlink_sane symlink target
  787.   #
  788.   # Ensure that the symbolic link symlink exists, and points to target.
  789.   #
  790.   # If symlink does not exist, create it and point it at target.
  791.   #
  792.   # If symlink exists but is not a symbolic link, back it up.
  793.   #
  794.   # If symlink exists, is a symbolic link, but points to the wrong location, fix
  795.   # it.
  796.   #
  797.   # If symlink exists, is a symbolic link, and already points to target, do
  798.   # nothing.
  799.   #
  800.   # This function wouldn't be needed if ln had an -I, --idempotent option.
  801.  
  802.   # Validate arguments.
  803.   if [ $# -ne 2 ]; then
  804.     usage_error "make_symlink_sane() called with wrong number of arguments;" \
  805.       "expected 2, got $#"
  806.     exit $SHELL_LIB_USAGE_ERROR
  807.   fi
  808.  
  809.   # We could just use the positional parameters as-is, but that makes things
  810.   # harder to follow.
  811.   #local symlink target
  812.  
  813.   _symlink="$1"
  814.   _target="$2"
  815.  
  816.   if [ -L "$_symlink" ] && [ "$(readlink "$_symlink")" = "$_target" ]; then
  817.       observe "link from $_symlink to $_target already exists"
  818.   else
  819.     observe "creating symbolic link from $_symlink to $_target"
  820.     mkdir -p "${_target%/*}" "${_symlink%/*}"
  821.     ln -s -b -S ".dpkg-old" "$_target" "$_symlink"
  822.   fi
  823. }
  824.  
  825. migrate_dir_to_symlink () {
  826.   # syntax: migrate_dir_to_symlink old_location new_location
  827.   #
  828.   # Per Debian Policy section 6.5.4, "A directory will never be replaced by a
  829.   # symbolic link to a directory or vice versa; instead, the existing state
  830.   # (symlink or not) will be left alone and dpkg will follow the symlink if
  831.   # there is one."
  832.   #
  833.   # We have to do it ourselves.
  834.   #
  835.   # This function moves the contents of old_location, a directory, into
  836.   # new_location, a directory, then makes old_location a symbolic link to
  837.   # new_location.
  838.   #
  839.   # old_location need not exist, but if it does, it must be a directory (or a
  840.   # symlink to a directory).  If it is not, it is backed up.  If new_location
  841.   # exists already and is not a directory, it is backed up.
  842.   #
  843.   # This function should be called from a package's preinst so that other
  844.   # packages unpacked after this one --- but before this package's postinst runs
  845.   # --- are unpacked into new_location even if their payloads contain
  846.   # old_location filespecs.
  847.  
  848.   # Validate arguments.
  849.   if [ $# -ne 2 ]; then
  850.     usage_error "migrate_dir_to_symlink() called with wrong number of"
  851.                 "arguments; expected 2, got $#"
  852.     exit $SHELL_LIB_USAGE_ERROR
  853.   fi
  854.  
  855.   # We could just use the positional parameters as-is, but that makes things
  856.   # harder to follow.
  857.   local _new _old
  858.  
  859.   _old="$1"
  860.   _new="$2"
  861.  
  862.   # Is old location a symlink?
  863.   if [ -L "$_old" ]; then
  864.     # Does it already point to new location?
  865.     if [ "$(readlink "$_old")" = "$_new" ]; then
  866.       # Nothing to do; migration has already been done.
  867.       observe "migration of $_old to $_new already done"
  868.       return 0
  869.     else
  870.       # Back it up.
  871.       warn "backing up symbolic link $_old as $_old.dpkg-old"
  872.       mv -b "$_old" "$_old.dpkg-old"
  873.     fi
  874.   fi
  875.  
  876.   # Does old location exist, but is not a directory?
  877.   if [ -e "$_old" ] && ! [ -d "$_old" ]; then
  878.       # Back it up.
  879.       warn "backing up non-directory $_old as $_old.dpkg-old"
  880.       mv -b "$_old" "$_old.dpkg-old"
  881.   fi
  882.  
  883.   observe "migrating $_old to $_new"
  884.  
  885.   # Is new location a symlink?
  886.   if [ -L "$_new" ]; then
  887.     # Does it point the wrong way, i.e., back to where we're migrating from?
  888.     if [ "$(readlink "$_new")" = "$_old" ]; then
  889.       # Get rid of it.
  890.       observe "removing symbolic link $_new which points to $_old"
  891.       rm "$_new"
  892.     else
  893.       # Back it up.
  894.       warn "backing up symbolic link $_new as $_new.dpkg-old"
  895.       mv -b "$_new" "$_new.dpkg-old"
  896.     fi
  897.   fi
  898.  
  899.   # Does new location exist, but is not a directory?
  900.   if [ -e "$_new" ] && ! [ -d "$_new" ]; then
  901.     warn "backing up non-directory $_new as $_new.dpkg-old"
  902.     mv -b "$_new" "$_new.dpkg-old"
  903.   fi
  904.  
  905.   # Create new directory if it does not yet exist.
  906.   if ! [ -e "$_new" ]; then
  907.     observe "creating $_new"
  908.     mkdir -p "$_new"
  909.   fi
  910.  
  911.   # Copy files in old location to new location.  Back up any filenames that
  912.   # already exist in the new location with the extension ".dpkg-old".
  913.   observe "copying files from $_old to $_new"
  914.   if ! (cd "$_old" && cp -a -b -S ".dpkg-old" . "$_new"); then
  915.     die "error(s) encountered while copying files from $_old to $_new"
  916.   fi
  917.  
  918.   # Remove files at old location.
  919.   observe "removing $_old"
  920.   rm -r "$_old"
  921.  
  922.   # Create symlink from old location to new location.
  923.   make_symlink_sane "$_old" "$_new"
  924. }
  925.  
  926. # vim:set ai et sw=2 ts=2 tw=80:
  927.  
  928. # GOBSTOPPER: The X Strike Force shell library ends here.
  929.  
  930. if [ "$1" = "install" ] || [ "$1" = "upgrade" ]; then
  931.  
  932.   # We need to remove /usr/X11R6/bin so we can replace it with a symlink
  933.   if [ -d "/usr/X11R6/bin" ] && [ ! -L /usr/X11R6/bin ]; then
  934.     if ! rmdir "/usr/X11R6/bin"; then
  935.       run db_fset x11-common/x11r6_bin_not_empty seen false
  936.       run db_input critical x11-common/x11r6_bin_not_empty
  937.       run db_go
  938.       exit 1
  939.     fi
  940.   fi
  941.  
  942.   # create the configuration files' main and auxiliary directories if they
  943.   # don't exist
  944.   for DIR in "$CONFIG_DIR" "$CONFIG_AUX_DIR"; do
  945.     if ! [ -e "$DIR" ]; then
  946.       observe "creating $DIR"
  947.       mkdir --mode=755 --parents "$DIR"
  948.     fi
  949.   done
  950.  
  951.   # symlink -> dir transition
  952.   for i in include share lib; do
  953.     if [ -L "/usr/${i}/X11" ]; then
  954.       rm /usr/${i}/X11
  955.     fi
  956.   done
  957.   # We provided this as a symlink in versions between 7.0.0 and 7.0.11. We want
  958.   # to be sure this is a directory after install to allow font packages to
  959.   # install properly even if they haven't transitioned
  960.   if [ -L "/usr/X11R6/lib/X11/fonts" ]; then
  961.     rm /usr/X11R6/lib/X11/fonts
  962.   fi
  963.  
  964.   # migration hilarity
  965.   if [ -n "$FIRSTINST" ]; then
  966.     for i in allowed_users actual_allowed_users nice_value; do
  967.       _TEMPLATE=xwrapper/$i
  968.       db_fget x11-common/$_TEMPLATE seen
  969.       if [ "$RET" = "false" ]; then
  970.         if db_fget xserver-common/$_TEMPLATE seen && [ "$RET" = "true" ]; then
  971.           if db_get xserver-common/$_TEMPLATE; then
  972.             _VALUE="$RET"
  973.             observe "migrating debconf question $_TEMPLATE from xserver-common"
  974.             db_set x11-common/$_TEMPLATE $_VALUE
  975.           fi
  976.         fi
  977.       fi
  978.     done
  979.  
  980.     if [ -e "/var/lib/xfree86" ]; then
  981.       if [ -e "/var/lib/xfree86/$XWRAPPER_CONFIG_ROSTER_BASE" ] && \
  982.          [ -e "/var/lib/xfree86/$XWRAPPER_CONFIG_CHECKSUM_BASE" ]; then
  983.         if fgrep -qx "xserver-common" \
  984.            "/var/lib/xfree86/$XWRAPPER_CONFIG_ROSTER_BASE"; then
  985.           # construct temporary roster file with our package name removed, ignoring
  986.           # failure
  987.           fgrep -vx "xserver-common" \
  988.             "/var/lib/xfree86/$XWRAPPER_CONFIG_ROSTER_BASE" > \
  989.             "/var/lib/xfree86/$XWRAPPER_CONFIG_ROSTER_BASE.dpkg-tmp" 2>/dev/null \
  990.             || true
  991.  
  992.           # is there anything left?
  993.           if [ -s "/var/lib/xfree86/$XWRAPPER_CONFIG_ROSTER_BASE.dpkg-tmp" ]; then
  994.             # yes, replace the roster file
  995.             mv "/var/lib/xfree86/$XWRAPPER_CONFIG_ROSTER_BASE.dpkg-tmp" \
  996.                "/var/lib/xfree86/$XWRAPPER_CONFIG_ROSTER_BASE"
  997.           else
  998.             # no; remove both the original and our temporary copy
  999.             rm -f "/var/lib/xfree86/$XWRAPPER_CONFIG_ROSTER_BASE" \
  1000.                   "/var/lib/xfree86/$XWRAPPER_CONFIG_ROSTER_BASE.dpkg-tmp"
  1001.  
  1002.             # migrate the checksum if it doesn't exist
  1003.             if [ -e "$XWRAPPER_CONFIG_CHECKSUM" ]; then
  1004.               rm "/var/lib/xfree86/$XWRAPPER_CONFIG_CHECKSUM_BASE"
  1005.             else
  1006.               mv "/var/lib/xfree86/$XWRAPPER_CONFIG_CHECKSUM_BASE" \
  1007.                  "$XWRAPPER_CONFIG_CHECKSUM"
  1008.             fi
  1009.           fi
  1010.         fi
  1011.       fi
  1012.  
  1013.       rmdir /var/lib/xfree86 2>/dev/null || true
  1014.     fi
  1015.   fi
  1016.  
  1017.   # place config files under management if they do *not* already exist
  1018.   if ! [ -e "$XWRAPPER_CONFIG" ]; then
  1019.     touch "$XWRAPPER_CONFIG"
  1020.     md5sum "$XWRAPPER_CONFIG" > "$XWRAPPER_CONFIG_CHECKSUM"
  1021.   fi
  1022. fi
  1023.  
  1024.  
  1025.  
  1026. exit 0
  1027.  
  1028. # vim:set ai et sts=2 sw=2 tw=0:
  1029.